package com.boot.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.boot.entity.Ad;
import com.boot.service.AdService;
import com.boot.util.AdResult;
import com.boot.util.CommonUtils;
import com.boot.util.PushServerConfig;

@Controller
public class MobileController {
	
	public static final String SERVER_URL=PushServerConfig.serverIp;
	
	@Resource
	private AdService adService;
	
	@RequestMapping("/mobile/checkAdInfo.do")
	public String checkAdInfo(ModelMap map,String ad_id){
		//System.out.println("ispush="+ispush+"id="+ad_id);
			AdResult result=adService.getAdById(ad_id);
			Ad ad = (Ad)result.getData();
			//System.out.println(result.getData());
			map.addAttribute("info",result);
			map.addAttribute("ad_id",ad_id);
			System.out.println(ad.getPull_time());
			map.addAttribute("date",CommonUtils.longToDate(ad.getPull_time()));
			map.addAttribute("serverUrl",SERVER_URL);
			//map.addAttribute("serverUrl",LOCAL_SERVER_URL);
			if(result.getStatus()==1){
				String photos = ad.getPhotos();
				if(photos!=null){
					String[] photosString = photos.split(",");
					List<String> photesList = new ArrayList<String>();
					for (String phote:photosString){
						photesList.add(phote);
					}
					map.addAttribute("photoStr",photos);
					map.addAttribute("photes",photesList);
				}
			}
			if(ad.getVideo()!=null){
				return "index/ad_detail_mv";
			}else{
				return "index/ad_detail_m";
			}
	}
	
}
